package pl.ydp.utils
{
	
	import asx.array.length;
	import asx.object.keys;
	
	import flexunit.framework.Assert;
	import flexunit.framework.TestCase;
	
	public class ObjectModelTest extends TestCase
	{		
		
		private var objectModel:ObjectModel;
		
		
		override public function setUp():void{
			super.setUp();
			
			objectModel = new ObjectModel();
		}
		
		
		public function testShouldNotNull():void
		{
			Assert.assertNotNull( objectModel.values );
			Assert.assertEquals( keys( objectModel.values ).length, 0 );
		}
		
		public function testShouldSetValue_normal():void
		{
//			given
			var key:String = 'key';
			var value:String = 'value';
			
//			when
			objectModel.setValue( key, value );
			
//			then
			Assert.assertEquals( keys( objectModel.values ).length, 1 );
			Assert.assertEquals( objectModel.getValue( key ),  value );
		}
		
		public function testShouldNotSetValue_emptyKey():void
		{
//			given
			var key:String = '';
			var value:String = 'value';
			
//			when
			objectModel.setValue( key, value );
			
//			then
			Assert.assertEquals( keys( objectModel.values ).length, 0 );
			Assert.assertNull( objectModel.getValue( key ) );
		}
		public function testShouldNotSetValue_nullKey():void
		{
//			given
			var key:String;
			var value:String = 'value';
			
//			when
			objectModel.setValue( key, value );
			
//			then
			Assert.assertEquals( keys( objectModel.values ).length, 0 );
			Assert.assertNull( objectModel.getValue( key ) );
		}
		
		public function testShouldGetNull():void
		{
			//			given
			
			//			when
			var value:* = objectModel.getValue( null );
			
			//			then
			Assert.assertEquals( keys( objectModel.values ).length, 0 );
			Assert.assertNull( value );
		}
		
		public function testShouldRemoveValue():void
		{
			//			given
			var key:String = 'key';
			var value:String = 'value';
			objectModel.setValue( key, value );
			
			//			when
			objectModel.removeValue( key );
			
			//			then
			Assert.assertEquals( keys( objectModel.values ).length, 0 );
		}
		
		public function testShouldNotRemoveValue():void
		{
			//			given
			var key:String = 'key';
			var keyToRemove:String = 'keyToRemove';
			var value:String = 'value';
			objectModel.setValue( key, value );
			
			//			when
			objectModel.removeValue( keyToRemove );
			
			//			then
			Assert.assertEquals( keys( objectModel.values ).length, 1 );
			Assert.assertEquals( objectModel.getValue( key ), value );
		}
		
		public function testShouldCheckKeyExists():void
		{
			//			given
			var key:String = 'key';
			var value:String = 'value';
			objectModel.setValue( key, value );
			
			//			when
			var exists:Boolean = objectModel.keyExists( key );
			
			//			then
			Assert.assertEquals( keys( objectModel.values ).length, 1 );
			Assert.assertTrue( exists );
		}
		
		public function testShouldCheckKeyNotExists():void
		{
			//			given
			var key:String = 'key';
			var value:String = 'value';
			objectModel.setValue( key, value );
			
			//			when
			var exists:Boolean = objectModel.keyExists( 'key2' );
			
			//			then
			Assert.assertEquals( keys( objectModel.values ).length, 1 );
			Assert.assertFalse( exists );
		}
		
	}
}
